<?php
namespace App\Http\Service;

use Illuminate\Http\Request;
use App\Http\Service\CommentService;
use App\Models\Node;

class PowerService
{
	private static $_obj;
	private $_node;
	private $_comment;

	public static function getInstance()
	{
		if (!self::$_obj instanceof self) {
			self::$_obj = new self();
		}
		return self::$_obj;
	}

	public function __construct()
	{
		$this->_node = Node::getInstance();
		$this->_comment = CommentService::getInstance();
	}

	/**
	 * 节点/权限添加操作
	 */
	public function addToPower(Request $data)
	{
		$result = $this->_node->addToPower($data);
		if ($result) {
			return $this->_comment->returnArr(200, '添加成功');
		} else {
			return $this->_comment->returnArr(300, '添加失败');
		}
	}

	/**
	 * 节点/权限编辑操作
	 */
	public function editPower(Request $data, $id)
	{
		$result = $this->_node->editPower($data, $id);
		if ($result) {
			return $this->_comment->returnArr(200, '编辑成功');
		} else {
			return $this->_comment->returnArr(300, '编辑失败');
		}
	}

	/**
	 * 节点权限删除操作
	 */
	public function delete($id)
	{
		$result = $this->_node->delPower($id);
		if ($result) {
			return $this->_comment->returnArr(200, '删除成功');
		} else {
			return $this->_comment->returnArr(300, '删除失败');
		}
	}

	/**
	 * 节点/权限状态修改
	 */
	public function status($id)
	{
		$result = $this->_node->statusPower($id);
		if ($result) {
			return $this->_comment->returnArr(200, '更改成功');
		} else {
			return $this->_comment->returnArr(300, '更改失败');
		}
	}
}